function [output] = trigen(A, w, A0, x)
n = prod(size(x));
T = 1/w;
for i = 1 : n
    while x(i) > T 
        x(i) = x(i) - T; 
    end
    while x(i) < 0 
        x(i) = x(i) + T; 
    end
    if x(i) < T/2
        output(i) = A*2/T*x(i);
    else
        output(i) = A*2/T*(T-x(i));
    end
end

output = output - A0/2;